//
//  Filter.swift
//  MacLandmarks
//
//  Created by taic8cai on 2020/6/29.
//  Copyright © 2020 Apple. All rights reserved.
//

import SwiftUI

struct Filter: View {
    @EnvironmentObject private var userData: UserData
    var body: some View {
        HStack{
            Toggle(isOn: $userData.showFavoritesOnly) {
                Text("Favorites Only")
            }
        }
    }
}

struct Filter_Previews: PreviewProvider {
    static var previews: some View {
        Filter().environmentObject(UserData())
    }
}

struct FilterType: Hashable, CaseIterable, Identifiable {
    var name: String
    var category: Landmark.Category?
    
    init(_ category: Landmark.Category) {
        self.name = category.rawValue
        self.category = category
    }
    
    init(name: String) {
        self.name = name
        self.category = nil
    }
    
    static var all = FilterType(name: "All")
    
    static var allCases: [FilterType] {
        return [.all] + Landmark.Category.allCases.map(FilterType.init)
    }
    
    var id: FilterType {
        return self
    }
    
}
